<?php
// MENU ITEMS:
$arr = array();
$result = db_query("SELECT node.nid AS nid,
   node_revisions.title AS title
 FROM node node 
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 WHERE (node.type in ('drzava'))
");
  while ($node = db_fetch_object($result))
  {
    $d['text'] = $node->title;
    $d['url'] = url('mesta', array('query' => array('id' => $node->nid)));
    $mesto_res = db_query("SELECT node.nid AS nid,
      node_revisions.title AS title
      FROM node node 
      LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
      LEFT JOIN content_type_mesto ON node.vid = content_type_mesto.vid
      WHERE (node.type in ('mesto')) AND content_type_mesto.field_drzava_nid = %d
      ", $node->nid);
    
    // da li ima dece?
    $i = 0;
    while($mesto = db_fetch_object($mesto_res))
    {
      $i = 1;
      $m['text'] = $mesto->title;
      $m['url'] = url('hoteli', array('query' => array('id' => $mesto->nid)));
      
      $d['submenu']['itemdata'][] = $m;
      unset($m);
    }
    if($i)
      $d['submenu']['id'] = $node->title.'menu';
    
    $arr[] = $d;
    unset($d);
  }

      $jsonresult = json_encode($arr);
      //print_r($jsonresult); die();
  
// $Id: page.tpl.php,v 1.18.2.1 2009/04/30 00:13:31 goba Exp $
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
  <head>
    <?php print $head ?>
    <title><?php print $head_title ?></title>
    <?php print $styles ?>
    <?php print $scripts ?>
    <!--[if lt IE 7]>
      <?php print phptemplate_get_ie_styles(); ?>
    <![endif]-->
  
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {

    var aItemData = <?php print_r($jsonresult); ?> /*[

        { text: "File", submenu: {  id: "filemenu", itemdata: [

                { text: "New File", helptext: "Ctrl + N" },
                "New Folder",
                { text: "Open", helptext: "Ctrl + O" },
                { text: "Open With...", submenu: { id: "applications", itemdata: [
                        "Application 1", 
                        "Application 2", 
                        "Application 3", 
                        "Application 4"
                    ] } 
                },
                { text: "Print", helptext: "Ctrl + P" }

            ] }
        
        },
        
        { text: "Edit", submenu: { id: "editmenu", itemdata: [

                [ 
                    { text: "Undo", helptext: "Ctrl + Z" },
                    { text: "Redo", helptext: "Ctrl + Y" }
                ],
                
                [
                    { text: "Cut", helptext: "Ctrl + X" },
                    { text: "Copy", helptext: "Ctrl + C" },
                    { text: "Paste", helptext: "Ctrl + V" },
                    { text: "Delete", helptext: "Del" }
                ],
                
                [ { text: "Select All", helptext: "Ctrl + A" } ],

                [
                    { text: "Find", helptext: "Ctrl + F" },
                    { text: "Find Again", helptext: "Ctrl + G" }
                ]
        
            ] }

        }

    ];*/


    // Instantiate a MenuBar, passing in the id of the element to be created

   
    var oMenuBar = new YAHOO.widget.MenuBar("mymenubar", { autosubmenudisplay: true }); 
    YAHOO.util.Dom.addClass(oMenuBar.element, "yuimenubarnav"); 
    

    // Add items to the MenuBar instance
    
    oMenuBar.addItems(aItemData);


    // Render the MenuBar instance
    
    oMenuBar.render('menu');

    
});
</script>

  </head>
  <body<?php print phptemplate_body_class($left, $right); ?>>

<!-- Layout -->
  <div id="header-region" class="clear-block"><?php print $header; ?></div>

    <div id="wrapper">
    <div id="container" class="clear-block">

      <div id="header">
        <div id="logo-floater">
        <?php
          // Prepare header
          $site_fields = array();
          if ($site_name) {
            $site_fields[] = check_plain($site_name);
          }
          if ($site_slogan) {
            $site_fields[] = check_plain($site_slogan);
          }
          $site_title = implode(' ', $site_fields);
          if ($site_fields) {
            $site_fields[0] = '<span>'. $site_fields[0] .'</span>';
          }
          $site_html = implode(' ', $site_fields);

          if ($logo || $site_title) {
            print '<h1><a href="'. check_url($front_page) .'" title="'. $site_title .'">';
            if ($logo) {
              print '<img src="'. check_url($logo) .'" alt="'. $site_title .'" id="logo" />';
            }
            print $site_html .'</a></h1>';
          }
        ?>
        </div>

        <?php if (isset($primary_links)) : ?>
          <?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>
        <?php endif; ?>
        <?php if (isset($secondary_links)) : ?>
          <?php print theme('links', $secondary_links, array('class' => 'links secondary-links')) ?>
        <?php endif; ?>

      </div> <!-- /header -->

      <?php if ($left): ?>
        <div id="sidebar-left" class="sidebar">
          <?php if ($search_box): ?><div class="block block-theme"><?php print $search_box ?></div><?php endif; ?>
          <?php print $left ?>
        </div>
      <?php endif; ?>

      <div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
          <div id="mymenubar" style="left:35px;position:absolute !important;top:12px;z-index:3;"></div>
          <?php //print $breadcrumb; ?>
          <?php if ($mission): print '<div id="mission">'. $mission .'</div>'; endif; ?>
          <?php if ($tabs): print '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
          <?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
          <?php if ($tabs): print '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
          <?php if ($tabs2): print '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
          <?php if ($show_messages && $messages): print $messages; endif; ?>
          <?php print $help; ?>
          <div class="clear-block">
            <?php print $content ?>
          </div>
          <?php print $feed_icons ?>
          <div id="footer"><?php print $footer_message . $footer ?></div>
      </div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->

      <?php if ($right): ?>
        <div id="sidebar-right" class="sidebar">
          <?php if (!$left && $search_box): ?><div class="block block-theme"><?php print $search_box ?></div><?php endif; ?>
          <?php print $right ?>
        </div>
      <?php endif; ?>

    </div> <!-- /container -->
  </div>
<!-- /layout -->

  <?php print $closure ?>
  </body>
</html>
